package com.gpzx.zx.module.home.ui.adapter

import android.content.Context
import android.text.TextUtils
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.gpzx.zx.databinding.*
import com.gpzx.zx.module.home.frame.model.QKLNewsInfo
import com.wkq.lib_base.adapter.KtDataBindingAdapter
import com.wkq.lib_base.adapter.KtDataBindingViewHolder
import com.wu.common.utils.DateTimeUtil

/**
 *
 * 作者:吴奎庆
 *
 * 时间:2020/6/8
 *
 * 用途:
 */


class QklNewsAdapter2(context: Context, layoutId: Int) : KtDataBindingAdapter<QKLNewsInfo>(context, layoutId) {

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        var bindingHolder = holder as KtDataBindingViewHolder
        var binding = bindingHolder.viewBinding as ItemQklNewsInfo2Binding
        binding.data = getItem(position)
//        var mTime = getItem(position)!!.news_time
//        if (!TextUtils.isEmpty(mTime)) {
//            if (getItem(position)!!.news_time!!.toLongOrNull() == null) {
//                binding.tvTime.setText(mTime)
//            } else {
//                var time = DateTimeUtil.formatDateTime(mTime!!.toLong() * 1000)
//                binding.tvTime.setText(time.toString())
//            }
//        }

        if (TextUtils.isEmpty(getItem(position)!!.news_icon)) {
            binding.ivIcon.visibility = View.GONE
        } else {
            if (!getItem(position)!!.news_icon!!.contains("https://cdn.55coin.com/article/img/0/15955975863731379.png")) {
                Glide.with(mContext).load(getItem(position)!!.news_icon).into(binding.ivIcon)
                binding.ivIcon.visibility = View.VISIBLE
            }
        }
        if (viewClickListener != null) {
            binding.root.setOnClickListener {
                viewClickListener?.onViewClick(binding.root, getItem(position))
            }
        }
    }

}